home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Interfaces / CIncludes / OSUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  13.7 KB  |  567 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        OSUtils.h
  3.  
  4.      Contains:    OS Utilities Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.1.4
  8.  
  9.      Copyright:    © 1984-1996 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. */
  19.  
  20. #ifndef __OSUTILS__
  21. #define __OSUTILS__
  22.  
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. /*    #include <ConditionalMacros.h>                                */
  28.  
  29. #ifndef __MIXEDMODE__
  30. #include <MixedMode.h>
  31. #endif
  32.  
  33. #ifndef __MEMORY__
  34. #include <Memory.h>
  35. #endif
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40.  
  41. #if PRAGMA_ALIGN_SUPPORTED
  42. #pragma options align=mac68k
  43. #endif
  44.  
  45. #if PRAGMA_IMPORT_SUPPORTED
  46. #pragma import on
  47. #endif
  48.  
  49.  
  50. enum {
  51.     useFree                        = 0,
  52.     useATalk                    = 1,
  53.     useAsync                    = 2,
  54.     useExtClk                    = 3,                            /*Externally clocked*/
  55.     useMIDI                        = 4,
  56. /* Environs Equates */
  57.     curSysEnvVers                = 2,                            /*Updated to equal latest SysEnvirons version*/
  58. /* Machine Types */
  59.     envMac                        = -1,
  60.     envXL                        = -2,
  61.     envMachUnknown                = 0,
  62.     env512KE                    = 1,
  63.     envMacPlus                    = 2,
  64.     envSE                        = 3,
  65.     envMacII                    = 4,
  66.     envMacIIx                    = 5,
  67.     envMacIIcx                    = 6,
  68.     envSE30                        = 7,
  69.     envPortable                    = 8,
  70.     envMacIIci                    = 9,
  71.     envMacIIfx                    = 11,
  72. /* CPU types */
  73.     envCPUUnknown                = 0
  74. };
  75.  
  76. enum {
  77.     env68000                    = 1,
  78.     env68010                    = 2,
  79.     env68020                    = 3,
  80.     env68030                    = 4,
  81.     env68040                    = 5,
  82. /* Keyboard types */
  83.     envUnknownKbd                = 0,
  84.     envMacKbd                    = 1,
  85.     envMacAndPad                = 2,
  86.     envMacPlusKbd                = 3,
  87.     envAExtendKbd                = 4,
  88.     envStandADBKbd                = 5,
  89.     envPrtblADBKbd                = 6,
  90.     envPrtblISOKbd                = 7,
  91.     envStdISOADBKbd                = 8,
  92.     envExtISOADBKbd                = 9,
  93.     false32b                    = 0,                            /*24 bit addressing error*/
  94.     true32b                        = 1,                            /*32 bit addressing error*/
  95. /* result types for RelString Call */
  96.     sortsBefore                    = -1,                            /*first string < second string*/
  97.     sortsEqual                    = 0,                            /*first string = second string*/
  98.     sortsAfter                    = 1                                /*first string > second string*/
  99. };
  100.  
  101. enum {
  102. /* Toggle results */
  103.     toggleUndefined                = 0,
  104.     toggleOK                    = 1,
  105.     toggleBadField                = 2,
  106.     toggleBadDelta                = 3,
  107.     toggleBadChar                = 4,
  108.     toggleUnknown                = 5,
  109.     toggleBadNum                = 6,
  110.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  111.     toggleErr3                    = 7,
  112.     toggleErr4                    = 8,
  113.     toggleErr5                    = 9,
  114. /* Date equates */
  115.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  116.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  117.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  118.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  119.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  120.     validDateFields                = -1,
  121.     maxDateField                = 10,
  122.     eraMask                        = 0x0001,
  123.     yearMask                    = 0x0002,
  124.     monthMask                    = 0x0004,
  125.     dayMask                        = 0x0008,
  126.     hourMask                    = 0x0010,
  127.     minuteMask                    = 0x0020,
  128.     secondMask                    = 0x0040,
  129.     dayOfWeekMask                = 0x0080,
  130.     dayOfYearMask                = 0x0100,
  131.     weekOfYearMask                = 0x0200,
  132.     pmMask                        = 0x0400,
  133.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  134. };
  135.  
  136. enum {
  137.     eraField,
  138.     yearField,
  139.     monthField,
  140.     dayField,
  141.     hourField,
  142.     minuteField,
  143.     secondField,
  144.     dayOfWeekField,
  145.     dayOfYearField,
  146.     weekOfYearField,
  147.     pmField,
  148.     res1Field,
  149.     res2Field,
  150.     res3Field
  151. };
  152.  
  153. typedef SignedByte LongDateField;
  154.  
  155.  
  156. enum {
  157.     dummyType,
  158.     vType,
  159.     ioQType,
  160.     drvQType,
  161.     evType,
  162.     fsQType,
  163.     sIQType,
  164.     dtQType,
  165.     nmType
  166. };
  167.  
  168. typedef SignedByte QTypes;
  169.  
  170.  
  171. enum {
  172.     OSTrap,
  173.     ToolTrap
  174. };
  175.  
  176. typedef SignedByte TrapType;
  177.  
  178. struct SysParmType {
  179.     UInt8                            valid;
  180.     UInt8                            aTalkA;
  181.     UInt8                            aTalkB;
  182.     UInt8                            config;
  183.     short                            portA;
  184.     short                            portB;
  185.     long                            alarm;
  186.     short                            font;
  187.     short                            kbdPrint;
  188.     short                            volClik;
  189.     short                            misc;
  190. };
  191. typedef struct SysParmType SysParmType, *SysPPtr;
  192.  
  193. typedef struct QElem QElem;
  194.  
  195. typedef QElem *QElemPtr;
  196.  
  197. struct QElem {
  198.     QElemPtr                        qLink;
  199.     short                            qType;
  200.     short                            qData[1];
  201. };
  202. typedef struct QHdr QHdr;
  203.  
  204. typedef QHdr *QHdrPtr;
  205.  
  206. struct QHdr {
  207.     short                            qFlags;
  208.     QElemPtr                        qHead;
  209.     QElemPtr                        qTail;
  210. };
  211. /*
  212.         DeferredTaskProcPtr uses register based parameters on the 68k and cannot
  213.         be written in or called from a high-level language without the help of
  214.         mixed mode or assembly glue.
  215.  
  216.             typedef pascal void (*DeferredTaskProcPtr)(long dtParam);
  217.  
  218.         In:
  219.          => dtParam         A1.L
  220. */
  221.  
  222. #if GENERATINGCFM
  223. typedef UniversalProcPtr DeferredTaskUPP;
  224. #else
  225. typedef Register68kProcPtr DeferredTaskUPP;
  226. #endif
  227.  
  228. struct DeferredTask {
  229.     QElemPtr                        qLink;
  230.     short                            qType;
  231.     short                            dtFlags;
  232.     DeferredTaskUPP                    dtAddr;
  233.     long                            dtParam;
  234.     long                            dtReserved;
  235. };
  236. typedef struct DeferredTask DeferredTask, *DeferredTaskPtr;
  237.  
  238. struct SysEnvRec {
  239.     short                            environsVersion;
  240.     short                            machineType;
  241.     short                            systemVersion;
  242.     short                            processor;
  243.     Boolean                            hasFPU;
  244.     Boolean                            hasColorQD;
  245.     short                            keyBoardType;
  246.     short                            atDrvrVersNum;
  247.     short                            sysVRefNum;
  248. };
  249. typedef struct SysEnvRec SysEnvRec;
  250.  
  251. struct MachineLocation {
  252.     Fract                            latitude;
  253.     Fract                            longitude;
  254.     union {
  255.         SInt8                            dlsDelta;                /*signed byte; daylight savings delta*/
  256.         long                            gmtDelta;                /*must mask - see documentation*/
  257.     } u;
  258. };
  259.  
  260. typedef struct MachineLocation MachineLocation;
  261.  
  262. struct DateTimeRec {
  263.     short                            year;
  264.     short                            month;
  265.     short                            day;
  266.     short                            hour;
  267.     short                            minute;
  268.     short                            second;
  269.     short                            dayOfWeek;
  270. };
  271. typedef struct DateTimeRec DateTimeRec;
  272.  
  273. typedef wide LongDateTime;
  274.  
  275. union LongDateCvt {
  276.     wide                            c;
  277.     struct {
  278.         UInt32                            lHigh;
  279.         UInt32                            lLow;
  280.     }                                hl;
  281. };
  282. typedef union LongDateCvt LongDateCvt;
  283.  
  284. union LongDateRec {
  285.     struct {
  286.         short                            era;
  287.         short                            year;
  288.         short                            month;
  289.         short                            day;
  290.         short                            hour;
  291.         short                            minute;
  292.         short                            second;
  293.         short                            dayOfWeek;
  294.         short                            dayOfYear;
  295.         short                            weekOfYear;
  296.         short                            pm;
  297.         short                            res1;
  298.         short                            res2;
  299.         short                            res3;
  300.     }                                ld;
  301.     short                            list[14];                    /*Index by LongDateField!*/
  302.     struct {
  303.         short                            eraAlt;
  304.         DateTimeRec                        oldDate;
  305.     }                                od;
  306. };
  307. typedef union LongDateRec LongDateRec;
  308.  
  309. typedef SInt8 DateDelta;
  310.  
  311. struct TogglePB {
  312.     long                            togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  313.     ResType                            amChars;                    /*from 'itl0', but uppercased*/
  314.     ResType                            pmChars;                    /*from 'itl0', but uppercased*/
  315.     long                            reserved[4];
  316. };
  317. typedef struct TogglePB TogglePB;
  318.  
  319. typedef short ToggleResults;
  320.  
  321. enum {
  322.     uppDeferredTaskProcInfo = kRegisterBased
  323.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(long)))
  324. };
  325.  
  326. #if GENERATINGCFM
  327. #define NewDeferredTaskProc(userRoutine)        \
  328.         (DeferredTaskUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDeferredTaskProcInfo, GetCurrentArchitecture())
  329. #else
  330. #define NewDeferredTaskProc(userRoutine)        \
  331.         ((DeferredTaskUPP) (userRoutine))
  332. #endif
  333.  
  334. #if GENERATINGCFM
  335. #define CallDeferredTaskProc(userRoutine, dtParam)        \
  336.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDeferredTaskProcInfo, (dtParam))
  337. #else
  338. /* (*DeferredTaskProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  339. #endif
  340.  
  341. extern pascal void LongDateToSeconds(const LongDateRec *lDate, LongDateTime *lSecs)
  342.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  343. extern pascal void LongSecondsToDate(LongDateTime *lSecs, LongDateRec *lDate)
  344.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  345. extern pascal ToggleResults ToggleDate(LongDateTime *lSecs, LongDateField field, DateDelta delta, short ch, const TogglePB *params)
  346.  FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  347. extern pascal short ValidDate(const LongDateRec *vDate, long flags, LongDateTime *newSecs)
  348.  FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  349. extern pascal Boolean IsMetric(void)
  350.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA9ED);
  351. extern pascal SysPPtr GetSysPPtr(void)
  352.  THREEWORDINLINE(0x2EBC, 0x0000, 0x01F8);
  353.  
  354. #if !GENERATINGCFM
  355. #pragma parameter __D0 ReadDateTime(__A0)
  356. #endif
  357. extern pascal OSErr ReadDateTime(unsigned long *time)
  358.  ONEWORDINLINE(0xA039);
  359.  
  360. #if !GENERATINGCFM
  361. #pragma parameter GetDateTime(__A0)
  362. #endif
  363. extern pascal void GetDateTime(unsigned long *secs)
  364.  TWOWORDINLINE(0x20B8, 0x020C);
  365.  
  366. #if !GENERATINGCFM
  367. #pragma parameter __D0 SetDateTime(__D0)
  368. #endif
  369. extern pascal OSErr SetDateTime(unsigned long time)
  370.  ONEWORDINLINE(0xA03A);
  371.  
  372. #if !GENERATINGCFM
  373. #pragma parameter SetTime(__A0)
  374. #endif
  375. extern pascal void SetTime(const DateTimeRec *d)
  376.  TWOWORDINLINE(0xA9C7, 0xA03A);
  377.  
  378. #if !GENERATINGCFM
  379. #pragma parameter GetTime(__A0)
  380. #endif
  381. extern pascal void GetTime(DateTimeRec *d)
  382.  THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  383. extern pascal void DateToSeconds(const DateTimeRec *d, unsigned long *secs);
  384.  
  385. #if !GENERATINGCFM
  386. #pragma parameter SecondsToDate(__D0, __A0)
  387. #endif
  388. extern pascal void SecondsToDate(unsigned long secs, DateTimeRec *d)
  389.  ONEWORDINLINE(0xA9C6);
  390. extern pascal void SysBeep(short duration)
  391.  ONEWORDINLINE(0xA9C8);
  392.  
  393.  
  394. #if !GENERATINGCFM
  395. #pragma parameter __D0 DTInstall(__A0)
  396. #endif
  397. extern pascal OSErr DTInstall(DeferredTaskPtr dtTaskPtr)
  398.  ONEWORDINLINE(0xA082);
  399.  
  400.  
  401. #if GENERATINGCFM
  402. #define GetMMUMode() ((char)true32b)
  403. #define SwapMMUMode(x) (*(SInt8*)(x) = true32b)
  404. #else
  405. extern pascal SInt8 GetMMUMode( void )
  406.     TWOWORDINLINE( 0x1EB8, 0x0CB2 ); /* MOVE.b $0CB2,(SP) */
  407.  
  408. #if !GENERATINGCFM
  409. #pragma parameter SwapMMUMode(__A0)
  410. #endif
  411. extern pascal void SwapMMUMode(SInt8 *mode)
  412.  THREEWORDINLINE(0x1010, 0xA05D, 0x1080);
  413. #endif
  414. #if SystemSixOrLater
  415.  
  416. #if !GENERATINGCFM
  417. #pragma parameter __D0 SysEnvirons(__D0, __A0)
  418. #endif
  419. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld)
  420.  ONEWORDINLINE(0xA090);
  421. #else
  422. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld);
  423. #endif
  424.  
  425. #if !GENERATINGCFM
  426. #pragma parameter Delay(__A0, __A1)
  427. #endif
  428. extern pascal void Delay(long numTicks, long *finalTicks)
  429.  TWOWORDINLINE(0xA03B, 0x2280);
  430. #if OLDROUTINENAMES && !GENERATINGCFM
  431.  
  432. #if !GENERATINGCFM
  433. #pragma parameter __A0 GetTrapAddress(__D0)
  434. #endif
  435. extern pascal UniversalProcPtr GetTrapAddress(UInt16 trapNum)
  436.  ONEWORDINLINE(0xA146);
  437.  
  438. #if !GENERATINGCFM
  439. #pragma parameter SetTrapAddress(__A0, __D0)
  440. #endif
  441. extern pascal void SetTrapAddress(UniversalProcPtr trapAddr, UInt16 trapNum)
  442.  ONEWORDINLINE(0xA047);
  443. #endif
  444. extern pascal UniversalProcPtr NGetTrapAddress(UInt16 trapNum, TrapType tTyp);
  445. extern pascal void NSetTrapAddress(UniversalProcPtr trapAddr, UInt16 trapNum, TrapType tTyp);
  446.  
  447. #if !GENERATINGCFM
  448. #pragma parameter __A0 GetOSTrapAddress(__D0)
  449. #endif
  450. extern pascal UniversalProcPtr GetOSTrapAddress(UInt16 trapNum)
  451.  ONEWORDINLINE(0xA346);
  452.  
  453. #if !GENERATINGCFM
  454. #pragma parameter SetOSTrapAddress(__A0, __D0)
  455. #endif
  456. extern pascal void SetOSTrapAddress(UniversalProcPtr trapAddr, UInt16 trapNum)
  457.  ONEWORDINLINE(0xA247);
  458.  
  459. #if !GENERATINGCFM
  460. #pragma parameter __A0 GetToolTrapAddress(__D0)
  461. #endif
  462. extern pascal UniversalProcPtr GetToolTrapAddress(UInt16 trapNum)
  463.  ONEWORDINLINE(0xA746);
  464.  
  465. #if !GENERATINGCFM
  466. #pragma parameter SetToolTrapAddress(__A0, __D0)
  467. #endif
  468. extern pascal void SetToolTrapAddress(UniversalProcPtr trapAddr, UInt16 trapNum)
  469.  ONEWORDINLINE(0xA647);
  470.  
  471. #if !GENERATINGCFM
  472. #pragma parameter __A0 GetToolboxTrapAddress(__D0)
  473. #endif
  474. extern pascal UniversalProcPtr GetToolboxTrapAddress(UInt16 trapNum)
  475.  ONEWORDINLINE(0xA746);
  476.  
  477. #if !GENERATINGCFM
  478. #pragma parameter SetToolboxTrapAddress(__A0, __D0)
  479. #endif
  480. extern pascal void SetToolboxTrapAddress(UniversalProcPtr trapAddr, UInt16 trapNum)
  481.  ONEWORDINLINE(0xA647);
  482. extern pascal OSErr WriteParam(void);
  483.  
  484. #if !GENERATINGCFM
  485. #pragma parameter Enqueue(__A0, __A1)
  486. #endif
  487. extern pascal void Enqueue(QElemPtr qElement, QHdrPtr qHeader)
  488.  ONEWORDINLINE(0xA96F);
  489.  
  490. #if !GENERATINGCFM
  491. #pragma parameter __D0 Dequeue(__A0, __A1)
  492. #endif
  493. extern pascal OSErr Dequeue(QElemPtr qElement, QHdrPtr qHeader)
  494.  ONEWORDINLINE(0xA96E);
  495. extern long SetCurrentA5(void)
  496.  THREEWORDINLINE(0x200D, 0x2A78, 0x0904);
  497.  
  498. #if !GENERATINGCFM
  499. #pragma parameter __D0 SetA5(__D0)
  500. #endif
  501. extern long SetA5(long newA5)
  502.  ONEWORDINLINE(0xC18D);
  503. #if !SystemSevenOrLater
  504. extern pascal void Environs(short *rom, short *machine);
  505. #endif
  506.  
  507. #if !GENERATINGCFM
  508. #pragma parameter __D0 InitUtil
  509. #endif
  510. extern pascal OSErr InitUtil(void)
  511.  ONEWORDINLINE(0xA03F);
  512. #if GENERATINGPOWERPC
  513. extern pascal void MakeDataExecutable(void *baseAddress, unsigned long length);
  514. #endif
  515. #if GENERATING68K
  516. extern pascal Boolean SwapInstructionCache(Boolean cacheEnable);
  517. extern pascal void FlushInstructionCache(void)
  518.  TWOWORDINLINE(0x7001, 0xA098);
  519. extern pascal Boolean SwapDataCache(Boolean cacheEnable);
  520. extern pascal void FlushDataCache(void)
  521.  TWOWORDINLINE(0x7003, 0xA098);
  522. extern pascal void FlushCodeCache(void)
  523.  ONEWORDINLINE(0xA0BD);
  524.  
  525. #if !GENERATINGCFM
  526. #pragma parameter FlushCodeCacheRange(__A0, __A1)
  527. #endif
  528. extern pascal void FlushCodeCacheRange(void *address, unsigned long count)
  529.  TWOWORDINLINE(0x7009, 0xA098);
  530. #endif
  531.  
  532. #if !GENERATINGCFM
  533. #pragma parameter ReadLocation(__A0)
  534. #endif
  535. extern pascal void ReadLocation(MachineLocation *loc)
  536.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA051);
  537.  
  538. #if !GENERATINGCFM
  539. #pragma parameter WriteLocation(__A0)
  540. #endif
  541. extern pascal void WriteLocation(const MachineLocation *loc)
  542.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA052);
  543. #if GENERATINGPOWERPC
  544. extern pascal UniversalProcPtr *GetTrapVector(UInt16 trapNumber);
  545. #endif
  546. #if OLDROUTINENAMES
  547. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  548. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  549. #define IUMetric() IsMetric()
  550. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  551. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  552. #endif
  553.  
  554. #if PRAGMA_IMPORT_SUPPORTED
  555. #pragma import off
  556. #endif
  557.  
  558. #if PRAGMA_ALIGN_SUPPORTED
  559. #pragma options align=reset
  560. #endif
  561.  
  562. #ifdef __cplusplus
  563. }
  564. #endif
  565.  
  566. #endif /* __OSUTILS__ */
  567.